<?php

namespace App\Console\Commands;

use App\Console\AdminPermissionDataInitCommand;
use App\Models\Role;
use DB;

class AdminInitRoles extends AdminPermissionDataInitCommand
{
    protected $relatedTables = [
        'model_has_roles',
    ];

    protected $signature = 'admin:roles {--f|force}';

    protected $description = '初始化后台角色设置';

    protected $dataFilePath = __DIR__.'/./data/roles.php';

    protected $model = Role::class;

    protected function handleRelation()
    {
        parent::handleRelation();

        $roleHasPermissionsData = require __DIR__.'/./data/role_has_permissions.php';

        $dbTable = DB::table('role_has_permissions');
        $dbTable->truncate();
        $dbTable->insert($roleHasPermissionsData);
    }
}
